package com.hzy.pay.controller;

import com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult;
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
import com.hzy.pay.wxpay.service.WeixinpayApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
public class PayController {
    @Autowired
    private WeixinpayApiService weixinpayApiService;

    @RequestMapping(value = "/wx/native")
    public void wxNative(HttpServletResponse response) throws Exception{
        System.out.println(weixinpayApiService.createNativeOrder(
                "商品信息", "1231231231", "0.01", "127.0.0.1", "ccccccccccc"
        ));
    }

    @RequestMapping(value = "/wx/app")
    public void wxApp(HttpServletResponse response) throws Exception{
        WxPayAppOrderResult wxPayAppOrderResult = weixinpayApiService.createAPPOrder(
                "商品信息", "1231231231", "0.01", "127.0.0.1"
        );
        System.out.println(wxPayAppOrderResult);
    }

    @RequestMapping(value = "/wx/h5")
    public void wxH5(HttpServletResponse response) throws Exception{
        String url = weixinpayApiService.createMWEBOrder(
                "商品信息", "1231231231", "0.01", "127.0.0.1"
        );
        System.out.println(url);
    }

    @RequestMapping(value = "/wx/jsapi")
    public void wxJsapi(HttpServletResponse response) throws Exception{
        WxPayMpOrderResult jsapiOrder = weixinpayApiService.createJSAPIOrder(
                "商品信息", "1231231231", "0.01", "127.0.0.1", "ccccccccccc"
        );
        System.out.println(jsapiOrder);
    }

    @RequestMapping(value = "/wx/query")
    public void orderQuery(HttpServletResponse response) throws Exception{
        weixinpayApiService.orderQuery("123123123");
    }

    @RequestMapping(value = "/wx/close")
    public void closeOrder(HttpServletResponse response) throws Exception{
        weixinpayApiService.closeOrder("123123123");
    }

    @RequestMapping(value = "/wx/refund")
    public void refund(HttpServletResponse response) throws Exception{
        weixinpayApiService.refund("123123123", "123123123", "0.01", "0.01");
    }

    @RequestMapping(value = "/wx/refundQuery")
    public void refundQuery(HttpServletResponse response) throws Exception{
        weixinpayApiService.refundQuery("123123123");
    }
}
